package com.aspose.cells;

import java.util.HashMap;

class zaay {
   public int a;
   public int b;
   public boolean c;
   public Worksheet d;
   public Cells e;
   public Object f;
   public int g;
   public short h;
   public boolean i;
   public boolean j;
   public boolean k;
   public CellArea l;
   public int m;
   public int n;
   public zur o;
   public zaax p;

   public zaay(Workbook var1, int var2, CalculationOptions var3) {
      this.a = 0;
      this.b = 0;
      this.c = true;
      this.g = 0;
      this.h = 0;
      this.i = false;
      this.j = false;
      this.k = false;
      this.l = CellArea.a;
      this.m = 0;
      this.n = -1;
      this.p = new zaax(var1, var2, var3);
      this.o = this.p.h;
   }

   public zaay(Worksheet var1, int var2, CalculationOptions var3) {
      this(var1.getWorkbook(), var2, var3);
      this.a(var1);
   }

   public zaay(zaay var1) {
      this.a = 0;
      this.b = 0;
      this.c = true;
      this.g = 0;
      this.h = 0;
      this.i = false;
      this.j = false;
      this.k = false;
      this.l = CellArea.a;
      this.m = 0;
      this.n = -1;
      this.a = var1.a;
      this.b = var1.b;
      this.c = var1.c;
      this.d = var1.d;
      this.e = var1.e;
      this.f = var1.f;
      this.g = var1.g;
      this.h = var1.h;
      this.i = var1.i;
      this.j = var1.j;
      this.k = var1.k;
      this.l = var1.l;
      this.n = var1.n;
      this.o = var1.o;
      this.p = var1.p;
   }

   public void a() {
      this.i = false;
      this.j = false;
      this.k = false;
      this.l = CellArea.a;
      this.m = 0;
   }

   public zaay b() {
      zaay var1;
      if (this.i) {
         if (this.l.b()) {
            var1 = new zaay(this);
            var1.l = CellArea.createCellArea(this.g, this.h, this.g + 2, this.h + 2);
            if (this.k) {
               var1.c();
            }

            return var1;
         } else {
            return this;
         }
      } else {
         var1 = new zaay(this);
         var1.i = true;
         if (!this.l.a() && !this.l.b()) {
            if (this.k) {
               var1.c();
            }
         } else {
            var1.l = CellArea.createCellArea(this.g, this.h, this.g + 2, this.h + 2);
         }

         return var1;
      }
   }

   public void a(Worksheet var1) {
      this.d = var1;
      this.n = var1.getIndex();
      this.o = this.a(this.p.i, this.n, this.n);
      this.e = var1.getCells();
   }

   public void c() {
      if (this.p.r) {
         this.m = 0;
      }

      if (this.l.c()) {
         this.m = 2;
      } else if (this.l.d()) {
         this.m = 1;
      } else {
         this.m = 3;
      }

   }

   public void a(int var1) {
      if ((var1 & this.m) != this.m) {
         if (this.m == 3) {
            this.m = var1;
         } else {
            this.m = 0;
         }

      }
   }

   public boolean d() {
      return this.p.Q.i.f == this.n && this.p.Q.i.g == this.g && this.p.Q.i.h == this.h;
   }

   public char e() {
      return (char)(this.p.v == 14 && this.a == 2 ? ' ' : ',');
   }

   public String a(String var1) {
      if (this.p.A == null) {
         this.p.A = new HashMap();
      }

      Object var2 = this.p.A.get(var1);
      if (var2 != null) {
         return (String)var2;
      } else {
         boolean var3 = false;
         if (this.p.v == 14) {
            var3 = zaan.a(var1);
         } else {
            var3 = zaan.a(var1, this);
         }

         String var4;
         if (var3) {
            var4 = '\'' + com.aspose.cells.b.a.zv.a(var1, "'", "''") + '\'';
         } else {
            var4 = var1;
         }

         this.p.A.put(var1, var4);
         return var4;
      }
   }

   zagu b(String var1) {
      zyd var2 = new zyd(this.p.g);
      boolean var3 = this.j;
      boolean var4 = this.k;
      this.j = false;
      this.k = false;

      try {
         if (!this.c) {
            if (var1.indexOf(82) == -1 && var1.indexOf(67) == -1) {
               zyz var12 = zzf.a;
               return var12;
            }

            var1 = zasp.b(var1, this.g, this.h);
         }

         byte[] var5 = var2.a(this.d.getIndex(), this.g, this.h, var1, (byte)0);
         zagu var13 = (new zyg(this, var5, 0, -1, false)).a();
         return var13;
      } catch (Exception var10) {
         zyz var6 = zzf.a;
         return var6;
      } finally {
         if (var3) {
            this.j = true;
            if (var4) {
               this.k = true;
            }
         }

      }
   }

   zaba f() {
      return (zaba)(this.p.j ? new zabb() : new zabc());
   }

   boolean g() {
      return this.p.s == 0 || this.p.Q.getCustomFunction() != null;
   }

   zyy a(DateTime var1) {
      return new zyy(CellsHelper.getDoubleFromDateTime(var1, this.p.l));
   }

   double b(DateTime var1) {
      return CellsHelper.getDoubleFromDateTime(var1, this.p.l);
   }

   boolean a(double var1) {
      return var1 >= 0.0D && var1 < this.p.n;
   }

   DateTime b(double var1) {
      return var1 == 0.0D ? this.p.o : CellsHelper.getDateTimeFromDouble(var1, this.p.l);
   }

   zur b(int var1) {
      return this.a(this.p.i, var1, var1);
   }

   zur a(int var1, int var2) {
      return this.a(this.p.i, var1, var2);
   }

   zur a(int var1, int var2, int var3) {
      zus var4 = this.p.g.q();
      int var5 = var4.e(var1, var2, var3);
      if (var5 > -1) {
         return var4.b(var5);
      } else {
         long var6 = (long)var1 << 32 | (long)(var3 << 16) | (long)var2;
         if (this.p.D != null) {
            Object var8 = this.p.D.get(var6);
            if (var8 != null) {
               return (zur)var8;
            }
         } else {
            this.p.D = new HashMap();
         }

         zur var9 = new zur(var1, var2, var3);
         this.p.D.put(var6, var9);
         return var9;
      }
   }

   void h() {
      zaay var1 = new zaay(this);
      int var2 = -1;
      if (this.p.M > 0) {
         for(int var3 = this.p.M - 1; var3 > -1; --var3) {
            if (this.p.L[var3] < this.p.x) {
               var2 = var3;
               break;
            }

            this.p.K[var3].b = false;
         }
      }

      while(true) {
         try {
            long var9 = this.p.c();
            Worksheet var5 = this.p.g.get(zyi.a(var9));
            zyi var6 = var5.getCells().b.a(zyi.b(var9));
            if (var6.c() != 2) {
               var6.a((byte)0);
               if (var5 != var1.d) {
                  var1.a(var5);
               }

               var6.b(var1);
            }

            --this.p.J;
            if (this.p.I < this.p.x) {
               if (this.p.w) {
                  this.p.c();
               }
               break;
            }
         } catch (zfk var7) {
            this.p.a();
            if (this.p.M > 0) {
               for(int var4 = this.p.M - 1; var4 > -1; --var4) {
                  if (this.p.L[var4] < this.p.x) {
                     var2 = var4;
                     break;
                  }

                  this.p.K[var4].b = false;
               }
            }
         } catch (zfg var8) {
            if (this.p.w) {
               this.p.e();
               return;
            }

            throw var8;
         }
      }

      this.p.b();
      this.p.M = var2 + 1;
   }

   void a(zyi param1) {
      // $FF: Couldn't be decompiled
   }

   void b(zyi var1) {
      if (var1.c() == 0) {
         try {
            var1.b(this);
         } catch (zfk var3) {
            this.h();
         } catch (zfg var4) {
            if (!this.p.Q.b) {
               throw new CellsException(5, com.aspose.cells.b.a.zr.a(this.a((StringBuilder)null)));
            }

            this.a((Exception)var4);
         } catch (CellsException var5) {
            if (!this.p.Q.b) {
               throw var5;
            }

            this.a(var5);
         } catch (Exception var6) {
            if (!this.p.Q.b) {
               throw new CellsException(5, com.aspose.cells.b.a.zr.a(this.c(new StringBuilder("Error in calculating cell [")).append("]: ").append(com.aspose.cells.a.c.zl.a(var6))));
            }

            this.a(var6);
         }
      } else if (var1.c() == 1) {
         throw new CellsException(5, com.aspose.cells.b.a.zr.a(this.a((StringBuilder)null)));
      }

   }

   zahn a(zyi var1, zagu var2) {
      this.p.d.a = var2;
      return this.a((zaie)this.p.d, (zyi)var1) ? this.p.d.b : null;
   }

   void b(zyi var1, zagu var2) {
      this.p.c.a = var2;
      this.a((zaie)this.p.c, (zyi)var1);
   }

   void a(zyi var1, zyg var2) {
      this.p.e.a = var2;
      this.a((zaie)this.p.e, (zyi)var1);
   }

   private boolean a(zaie var1, zyi var2) {
      try {
         this.p.a(zyi.a(this.n, var2.a));
         var1.a(this, var2);
         this.p.c();
         return true;
      } catch (zfk var4) {
         throw var4;
      } catch (zfg var5) {
         if (this.p.p) {
            if (!this.p.w && var5.a == var2) {
               this.a(var2);
               return false;
            }
         } else {
            var1.b(this, var2);
            this.p.c();
            if (var5.a == var2) {
               com.aspose.cells.a.c.zl.a(com.aspose.cells.b.a.zr.a(this.a((StringBuilder)null)));
               return false;
            }
         }

         throw var5;
      } catch (CellsException var6) {
         if (this.p.Q.b) {
            this.a(var6);
            var1.b(this, var2);
            this.p.c();
            return false;
         } else {
            throw var6;
         }
      } catch (Exception var7) {
         if (this.p.Q.b) {
            this.a(var7);
            var1.b(this, var2);
            this.p.c();
            return false;
         } else {
            throw new CellsException(5, com.aspose.cells.b.a.zr.a(this.c(new StringBuilder("Error in calculating Cell[")).append("]")), var7);
         }
      }
   }

   StringBuilder a(StringBuilder var1) {
      if (var1 == null) {
         var1 = new StringBuilder();
      }

      return this.c(var1.append("Circular Reference for "));
   }

   StringBuilder b(StringBuilder var1) {
      if (var1 == null) {
         var1 = new StringBuilder();
      }

      if (this.a == 1) {
         var1.append("Name[").append(this.f).append("] based on ");
      }

      var1.append('[').append(this.n).append(']').append(this.d.getName()).append('!').append(CellsHelper.cellIndexToName(this.g, this.h));
      return var1;
   }

   StringBuilder c(StringBuilder var1) {
      var1 = this.b(var1);
      if (this.a == 0 && this.p.I > 1) {
         long var2 = this.p.H[this.p.I - 1];
         int var4 = zyi.a(var2);
         zyi var6;
         if (var4 != this.n) {
            Worksheet var5 = this.p.g.get(var4);
            var1.append("<-");
            var1.append(var5.getName());
            var1.append('!');
            var6 = var5.getCells().b.a(zyi.b(var2));
            var1.append(CellsHelper.cellIndexToName(var6.e, var6.f));
         } else {
            int var7 = zyi.b(var2);
            if (var7 != ((zyi)this.f).a) {
               var1.append("<-");
               var6 = this.e.b.a(zyi.b(var2));
               var1.append(CellsHelper.cellIndexToName(var6.e, var6.f));
            }
         }
      }

      return var1;
   }

   void a(CellsException var1) {
      if (this.p.Q.i.a) {
         if (var1.getCode() == 5) {
            com.aspose.cells.a.c.zl.a(var1.getMessage());
         } else {
            com.aspose.cells.a.c.zl.a(com.aspose.cells.b.a.zr.a(this.c((new StringBuilder("CellsException[Code:")).append(var1.getCode()).append(",Message:").append(var1.getMessage()).append("] for Cell[")).append("]")));
         }
      }

   }

   void a(Exception var1) {
      if (this.p.Q.i.a) {
         com.aspose.cells.a.c.zl.a(com.aspose.cells.b.a.zr.a(this.c(new StringBuilder("Error in calculating Cell[")).append("]: ").append(com.aspose.cells.a.c.zl.a(var1))));
      }

   }
}
